package com.lin.healthmanagement.controller;

import com.lin.healthmanagement.controller.code.Code;
import com.lin.healthmanagement.controller.code.Message;
import com.lin.healthmanagement.controller.exception.BusinessException;
import com.lin.healthmanagement.controller.result.Result;
import com.lin.healthmanagement.dao.MenuDao;
import com.lin.healthmanagement.entity.MainMenu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class MenuController {

    @Autowired
    MenuDao menuDao;

    @GetMapping("/menus")
    public Result getAllMenus(){
        Integer data=Code.SYSTEM_BUSY;
        String msg=Message.Error;
        List<MainMenu> menus=new ArrayList<>();
        try {
            menus=menuDao.getMenus();
            if(menus != null){
                data= Code.GET_OK;
                msg= Message.ok;
            }
        } catch (BusinessException e) {
            throw new BusinessException(data,msg);
        } catch (Exception e){
            throw e;
        }
        return new Result(data,msg,menus);
    }
}
